package com.tony.pmp.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tony.pmp.common.utils.PageUtil;
import com.tony.pmp.common.utils.QueryUtil;
import com.tony.pmp.model.entity.SysLogEntity;
import com.tony.pmp.model.mapper.SysLogMapper;
import com.tony.pmp.server.service.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: SysLogServiceImpl
 * @Auther: 皮蛋布丁
 * @Date: 2021/08/02/20:50
 * @Description:
 */
@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLogEntity> implements SysLogService {

    /**
    * @Description: queryPage 获取日志信息列表
    * @Param: [params]
    * @return: com.tony.pmp.common.utils.PageUtil
    * @Author: 皮蛋布丁
    * @Date: 2021/8/2 22:06
    */
    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");

        IPage queryPage = new QueryUtil<SysLogEntity>().getQueryPage(params);

        QueryWrapper<SysLogEntity> wrapper = new QueryWrapper<SysLogEntity>()
                .like(StringUtils.isNotBlank(key),"username",key)
                .or(StringUtils.isNotBlank(key))
                .like(StringUtils.isNotBlank(key),"operation",key);
        IPage<SysLogEntity> page = this.page(queryPage,wrapper);
        return new PageUtil(page);
    }

    /**
    * @Description: truncate 清除日志信息
    * @Param: []
    * @return: boolean
    * @Author: 皮蛋布丁
    * @Date: 2021/8/2 22:25
    */
    @Override
    public boolean truncate() {
        return baseMapper.truncate();
    }
}
